import React from "react";
import { Link, Routes, Route, Outlet } from "react-router-dom";

const Home1 = () => {
  return <div>这是home1页面</div>;
};

const Home2 = () => {
  return <div>这是home2页面</div>;
};

const Home = () => {
  return (
    <>
      <div>这是home页面</div>
      <ul>
        <li>
          <Link to="/home">home1</Link>
        </li>
        <li>
          <Link to="/home/home2">home2</Link>
        </li>
      </ul>

      <hr />

      {/* 相当于router-view */}
      <Outlet />
    </>
  );
};

const About = () => {
  return <div>这是about页面</div>;
};

const App = () => {
  return (
    <>
      <h2>react-router-v6-nest</h2>
      <ul>
        <li>
          <Link to="/home">home</Link>
        </li>
        <li>
          <Link to="/about">about</Link>
        </li>
      </ul>

      <hr />

      <Routes>
        {/* 整个项目的路由，现在是在一处进行维护 */}
        <Route path="/home" element={<Home />}>
          {/* 如果二级路由的地址和一级路由时一致的，那么可以加上index属性 */}
          {/* 不是以斜杠开头，相当于是在上一级的基础上做拼接 */}
          <Route index element={<Home1 />}></Route>
          <Route path="home2" element={<Home2 />}></Route>
        </Route>
        <Route path="/about" element={<About />}></Route>
      </Routes>
    </>
  );
};

export default App;
